<?php
declare (strict_types=1);

namespace app\api\controller\v2;

use app\common\model\Question;

class WordExam extends BaseController
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        return sucessMsg(200, '获取成功', [
            'neirong' => $this->group(),   //获取单词认读测试
        ]);
    }

    /**
     * 获取单词认读测试
     *
     * @return \think\Response
     */
    public function group()
    {
        //列表
        $model = new Question();
        $page = input('page/d', 1);
        $pageSize = input('pageSize/d', 1);
        $data = $model->where(['status' => 1, 'mold_id' => 1])
            ->field('id,name,title,answer,A,B,C,D,mold_id')
            ->order('id', 'asc')
            ->page($page, $pageSize)
            ->select();
        $rows = count($model->where('mold_id')->select()->toArray());
        $maxPage = ceil($rows / $pageSize);
        return ['data' => $data, 'total' => count($data), 'page' => $page, 'pageSize' => $pageSize, 'maxPage' => $maxPage];
    }
}
